//
// Created by le on 13/12/2022.
//

#ifndef PLANEGAME_PLAYER_HPP
#define PLANEGAME_PLAYER_HPP
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h>
#include <random>
#include <vector>

#ifdef __WIN32
#define Main SDL_main
#endif

#ifndef __WIN32
#define Main main
#endif

#define FRAMERATE 60 // 帧率

// 玩家类
class Player
{
public:
    Player(SDL_Renderer *renderer) : m_playerRenderer(renderer), m_imageSurface(NULL), m_imageTexture(NULL)
    {
        m_imageSurface = IMG_LoadPNG_RW(SDL_RWFromFile("../static/myPlane.png", "rb"));
        if (!m_imageSurface)
        {
            exit(-1);
        }

        m_w = m_imageSurface->w;
        m_h = m_imageSurface->h;

        m_imageTexture = SDL_CreateTextureFromSurface(m_playerRenderer, m_imageSurface);
        SDL_FreeSurface(m_imageSurface);
        m_imageSurface = NULL;
    }

    ~Player()
    {
        if (m_imageTexture)
        {
            SDL_DestroyTexture(m_imageTexture);
        }
    }

    void render(Sint32 x, Sint32 y)
    {
        SDL_ShowCursor(false);

        SDL_Rect srcrect = {x, y, m_w, m_h};
        SDL_RenderCopy(m_playerRenderer, m_imageTexture, NULL, &srcrect);
    }

private:
    SDL_Surface *m_imageSurface;
    SDL_Texture *m_imageTexture;

    SDL_Renderer *m_playerRenderer;

public:
    int m_w;
    int m_h;
};

#endif // PLANEGAME_PLAYER_HPP
